/**
 * Created With IntelliJ IDEA
 * Description:leetcode：434. 字符串中的单词数
 * <a href="https://leetcode.cn/problems/number-of-segments-in-a-string/">...</a>
 * User: DELL
 * Data: 2022-11-21
 * Time: 0:39
 */
class Solution {
    public int countSegments(String s) {
        int count = 0;

        for (int i = 0; i < s.length(); i++) {
            if ((i == 0 || s.charAt(i - 1) == ' ') && s.charAt(i) != ' ') {
                count++;
            }
        }

        return count;
    }
}
